-
-
Notifications
You must be signed in to change notification settings - Fork 195
[sm9171] Week01 Solutions #1158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
상민님 안녕하세요-!!
잘 지내시나요 ㅎㅎㅎ
지나가다가 리뷰 남겼어요!
끝까지... 파이팅입니다🔥
(github action 실패한 건 아마 마지막 라인에 개행을 안 해서 그런 것 같아요!)
HashSet<Integer> set = new HashSet<>(); | ||
|
||
for (int i = 0; i < nums.length; i++) { | ||
set.add(nums[i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add 할 때 존재하는지 확인하고 바로 return 하는 건 어떨까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wisdon08님이 좋은 의견 남겨주신것에 저도 동의합니다!
현재는 배열을 끝까지 순회한 후에 중복을 판단하는 구조인것 같아서, 중복을 미리 찾고 빠르게 결과 반환을 하는 구조로 변경하는 것도 좋아 보입니다 😀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
두 분 의견 감사합니다. 얘기 해주신대로 얼리 리턴을 하니 17ms에서 12ms로 단축 되었네요 :)
top-k-frequent-elements/sm9171.java
Outdated
for (int i = 0; i < nums.length; i++) { | ||
int num = nums[i]; | ||
if (hashMap.containsKey(num)) { | ||
hashMap.put(num, hashMap.get(num) + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hashMap.getOrDefault
를 이용해서 가독성을 개선할 수도 있을 거 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getOrDefault를 쓰니 한줄로 줄일 수 있겠네요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
안녕하세요. 어느덧 1주차 문제풀이 마지막 날이네요.
지금까지 제출해주신 문제들을 기준으로 리뷰 남겼습니다.
다른 문제들도 풀이해주시면 확인 후 추가로 리뷰 진행하겠습니다! 😃
HashSet<Integer> set = new HashSet<>(); | ||
|
||
for (int i = 0; i < nums.length; i++) { | ||
set.add(nums[i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wisdon08님이 좋은 의견 남겨주신것에 저도 동의합니다!
현재는 배열을 끝까지 순회한 후에 중복을 판단하는 구조인것 같아서, 중복을 미리 찾고 빠르게 결과 반환을 하는 구조로 변경하는 것도 좋아 보입니다 😀
result[i] = list.get(i); | ||
} | ||
|
||
return result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
위에 List list 부분에서 stream을 사용하신 것 처럼, 반환값도 stream을 활용해보시는 건 어떨까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네 array로 타입 변경하는 부분도 스트림을 이용하여 해결해 보았습니다 :)
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!